package com.minimalist.common.config.bucket;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;
import java.util.Objects;

/**
 * @author 11987
 */
@Configuration
@ConfigurationProperties(prefix = "rate-limit")
public class RateLimitConfig{
    private int capacity;
    private Duration refillInterval;

    public RateLimitConfig(){
    }

    public RateLimitConfig(int capacity, Duration refillInterval){
        this.capacity = capacity;
        this.refillInterval = refillInterval;
    }

    public int getCapacity(){
        return capacity;
    }

    public void setCapacity(int capacity){
        this.capacity = capacity;
    }

    public Duration getRefillInterval(){
        return refillInterval;
    }

    public void setRefillInterval(Duration refillInterval){
        this.refillInterval = refillInterval;
    }

    @Override
    public boolean equals(Object o){
        if (this == o){
            return true;
        }
        if (o == null || getClass() != o.getClass()){
            return false;
        }
        RateLimitConfig that = (RateLimitConfig) o;
        return capacity == that.capacity && refillInterval == that.refillInterval;
    }

    @Override
    public int hashCode(){
        return Objects.hash(capacity, refillInterval);
    }

    @Override
    public String toString(){
        return "RateLimitConfig{" +
                "capacity=" + capacity +
                ", refillInterval=" + refillInterval +
                '}';
    }
}
